<style scoped>
    .role-managment-page {
    }
    .clean {
        clear: both;
        height: 0;
        line-height: 0;
        font-size: 0;
    }
    .role-managment-page .condition {
        line-height: 36px;
    }
    .role-managment-page .empoerWindows .el-dialog {
        width: 30%;
        height: 500px;
    }
    .role-managment-page .empoerWindows .el-transfer {
        margin:32px 20% 80px;
    }
    .role-managment-page .empoerWindows .el-select {
        margin-left: 155px;
    }


    /* 分配菜单权限 */
    
    .empoerWindows .el-dialog.el-dialog--tiny .el-dialog__body{padding:10px 20px;}
    .empoerWindows .el-dialog.el-dialog--tiny h2{line-height:36px;}
    .empoerWindows .el-dialog.el-dialog--tiny .content{padding:10px;height:340px;border:1px solid #ccc;overflow-x:hidden;overflow-y:scroll;}
    .empoerWindows .el-dialog.el-dialog--tiny .content .el-tree{border:none;}
    .empoerWindows .el-dialog.el-dialog--tiny .content .pLeft24{padding-left:24px;}
    .empoerWindows .el-dialog.el-dialog--tiny .content .el-checkbox-group{padding-left:24px;}
    .empoerWindows .el-dialog.el-dialog--tiny .content .el-checkbox-group label{display:block;margin-bottom:10px;}
    .empoerWindows .el-dialog.el-dialog--tiny .content .el-checkbox-group .el-checkbox+.el-checkbox{margin-left:0;}
    .empoerWindows .el-dialog.el-dialog--tiny .btn-box{width:300px;margin:10px auto auto;}
    .empoerWindows .el-dialog.el-dialog--tiny .btn-box .el-button{}
</style>

<template>
    <!--  角色管理 -->
    <div class="role-managment-page">
        <el-form :inline="true" :model="formInline" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
            <!--角色名称-->
            <el-form-item :label="nowLangue.roleName" class="selectMB10">
                <el-input size="mini" v-model="formInline.name" :placeholder="nowLangue.pleaseImport+nowLangue.roleName"></el-input>
            </el-form-item>
            <!--角色代码-->
            <el-form-item :label="nowLangue.roleCode" class="selectMB10">
                <el-input size="mini" v-model="formInline.code" :placeholder="nowLangue.pleaseImport+nowLangue.roleCode"></el-input>
            </el-form-item>
            <!--当前状态-->
            <el-form-item :label="nowLangue.currStatus" class="selectMB10">
                <el-select size="mini" clearable v-model="formInline.status" :placeholder="nowLangue.pleaseSelect">
                    <!--启用-->
                    <el-option :label="nowLangue.enable" value="true"></el-option>
                    <!--禁用-->
                    <el-option :label="nowLangue.forbidden" value="false"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item class="selectMB10">
                <!--查询-->
                <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="handleQuery" v-text="nowLangue.query"></el-button>
            </el-form-item>
        </el-form>
        <!--表格-->
        <!--角色列表：-->
        <label class="default-label" v-text="nowLangue.roleList"></label>
        <!--新增角色按钮-->
        <!--新增角色-->
        <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="powerFlag" @click="handleAdd()" v-text="nowLangue.create"></el-button>
        <el-table :data="tableData" border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <!--序-->
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence"  width="40"></el-table-column>
            <!--操作-->
            <el-table-column :label="nowLangue.operate" header-align="center" align="center" width="150">
                <template scope="scope">
                    <!--禁用-->
                    <button class="operationItem bolder" v-if="scope.row.roleStatus && powerFlag" @click="handleDisable(scope.$index, scope.row)" v-text="nowLangue.forbidden" :disabled="statusDisabled"></button>
                    <!--启用-->
                    <button class="operationItem bolder" v-else-if="!scope.row.roleStatus && powerFlag" @click="handleOpen(scope.$index, scope.row)" v-text="nowLangue.enable" :disabled="statusDisabled"></button>
                    <!--修改-->
                    <button class="operationItem bolder" v-if="!scope.row.roleStatus && powerFlag" @click="handleEdit(scope.$index, scope.row)" v-text="nowLangue.update"></button>
                    <!--修改-->
                    <button class="operationItem disabled bolder" v-else-if="scope.row.roleStatus && powerFlag" v-text="nowLangue.update"></button>
                    <!--赋权-->
                    <button class="operationItem bolder" v-if="powerFlag" @click="handleFQ(scope.$index, scope.row)" v-text="nowLangue.empowerment"></button>
                    <!--查看-->
                    <button class="operationItem bolder" @click="handleSee(scope.$index, scope.row)" v-text="nowLangue.lookUp"></button>
                </template>
            </el-table-column>
            <!--角色名称-->
            <el-table-column prop="roleName" :label="nowLangue.roleName" header-align="center" show-overflow-tooltip></el-table-column>
            <!--角色代码-->
            <el-table-column prop="roleCode" :label="nowLangue.roleCode" header-align="center" show-overflow-tooltip></el-table-column>
            <!--当前状态-->
            <el-table-column prop="status" :label="nowLangue.currStatus" header-align="center" align="center" width="80" show-overflow-tooltip></el-table-column>
        </el-table>
        <!--分页-->
        <el-pagination v-if="isPaging" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageIndex" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="totalPage" :total="totalNumber"></el-pagination>

        <!--新增或者修改角色的弹框-->
        <el-dialog :title="title" :visible.sync="dialogFormVisible" size="tiny" :lock-scroll="false">
            <el-form :model="form" ref="form" :inline="true"  class="demo-form-inline label-minW90">
                <!--角色名称-->
                <el-form-item :label="nowLangue.roleName" prop="roleName" :rules="[{ required: true, message: nowLangue.required},{ min: 1, message: nowLangue.greaterThan1},{ max: 100, message: nowLangue.lessThan100},{ validator: checkName, trigger: 'blur' }]">
                    <el-input size="mini" class="role-name" v-model.trim="form.roleName" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.roleName"></el-input>
                </el-form-item>
                <!--角色代码-->
                <el-form-item :label="nowLangue.roleCode"  prop="roleCode"  :rules="[{ required: true, message: nowLangue.required},{ min: 1, message: nowLangue.greaterThan1},{ max: 20, message: nowLangue.lessThan20},{ validator: checkCode, trigger: 'blur' }]" >
                    <el-input size="mini" class="role-code" v-model.trim="form.roleCode" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.roleCode"></el-input>
                </el-form-item>
                <!--状态-->
                <el-form-item :label="nowLangue.status"  prop="allStatus">
                    <!--启用-->
                    <el-radio class="radio" v-model="allStatus" label="start" v-cloak>{{nowLangue.enable}}</el-radio>
                    <!--禁用-->
                    <el-radio class="radio" v-model="allStatus" label="disable" v-cloak>{{nowLangue.forbidden}}</el-radio>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!--返 回-->
                <el-button class="bolder outsideBtnBS" size="mini" @click="dialogFormVisible = false" v-text="nowLangue.return"></el-button>
                <!--保 存-->
                <el-button class="bolder outsideBtnBS" size="mini" v-if="saveButtonFlag" type="danger" @click="saveAddRoleAdd()" v-text="nowLangue.save" :disabled="addSaveDisabled"></el-button>
                <!--保 存-->
                <el-button class="bolder outsideBtnBS" size="mini" v-else type="danger" @click="saveAddRoleUpdate()" v-text="nowLangue.save" :disabled="updateSaveDisabled"></el-button>
            </div>
        </el-dialog>

        <!--赋权按钮弹窗-->
        <!--分配菜单权限-->
        <el-dialog :title="nowLangue.assignMenuPermissions" :visible.sync="empowerVisible" class="clearfix empoerWindows" size="tiny" :lock-scroll="false">
            <!--角色名称：-->
            <h2 v-text="nowLangue.roleName+'：'+roleName"></h2>
            <div class="content">
                <!-- check-strictly 在显示复选框的情况下，是否严格的遵循父子不互相关联的做法，默认为 false -->
                <el-tree :data="bigPowers" show-checkbox default-expand-all node-key="id" ref="tree" highlight-current :default-checked-keys="permissionIdList" :props="defaultProps" check-strictly> </el-tree>
            </div>
            <div slot="footer" class="dialog-footer">
                <!--确定-->
                <el-button class="bolder outsideBtnBS" type="danger" size="mini" @click="handleConfirmFQ" v-text="nowLangue.confirm" :disabled="confirmFQDisabled"></el-button>
                <!--取消-->
                <el-button class="bolder outsideBtnBS" size="mini" @click="cancelFQ" v-text="nowLangue.cancel"></el-button>
            </div>
        </el-dialog>
        <!-- 查看弹窗 -->
        <!--查看角色权限-->
        <el-dialog :title="nowLangue.viewRolePermissions" :visible.sync="seeVisible" class="clearfix empoerWindows" size="tiny" :lock-scroll="false">
            <!--角色名称：-->
            <h2 v-text="nowLangue.roleName+'：'+roleName"></h2>
            <div class="content">
                <el-tree :data="seeBigPowers" :props="defaultProps" default-expand-all> </el-tree>
            </div>
        </el-dialog>
    </div>
</template>
<script>
    export default {
        data() {
            var _this=this;

            var checkName = (rule, value, callback) => {

                if (!value) {
                    var tip=_this.languageType=="zh"?'角色名称不能为空':'Role name cannot be empty';
                    return callback(new Error(tip));
                }
                setTimeout(() => {
                    //判断是否已经存在
                    var id = _this.form.id;
                    var tmp = {id:id,roleName:value};
                    $.ajax({
                        type: 'POST',
                        async:false,
                        url: _this.metadata_service+"role/searchIfExist",
                        cache: false,
                        data:JSON.stringify(tmp),
                        dataType:'JSON',
                        contentType: "application/json;charset=utf-8",
                        success: function (data) {
                            //存在时候给友好提示
                            if (!data.success) {
                                callback(new Error(data.errorMessage));
                            }else{
                                callback();
                            }
                        }

                    });
                    callback();
                }, 1000);
            };
            var checkCode = (rule, value, callback) => {
                if (!value) {
                    var tip=_this.languageType=="zh"?'角色代码不能为空':'Role code cannot be empty';
                    return callback(new Error(tip));
                }
                setTimeout(() => {
                    var re =  /^[0-9a-zA-Z]*$/g;  //判断字符串是否为数字和字母组合
                    if (!re.test(value)){
                        var tip2=_this.languageType=="zh"?'请输入数字或字母组合':'Please enter a combination of numbers or letters';
                        callback(new Error(tip2));
                    } else {
                        //判断是否已经存在
                        var id = _this.form.id==null?"":_this.form.id;
                        var tmp = {id:id,roleCode:value};
                        $.ajax({
                            type: 'POST',
                            async:false,
                            url: _this.metadata_service+"role/searchIfExist",
                            cache: false,
                            data:JSON.stringify(tmp),
                            dataType:'JSON',
                            contentType: "application/json;charset=utf-8",
                            success: function (data) {
                                //存在时候给友好提示
                                if (!(data.success)) {
                                    callback(new Error(data.errorMessage));
                                }else{
                                    callback();
                                }
                            }
                        });
                        callback();
                    }
                }, 1000);
            };
            return {
                nowLangue:{},
                checkName:checkName,
                checkCode:checkCode,
                formInline: {
                    roleName: '',
                    roleCode: '',
                    status: ''
                },
                saveButtonFlag: true,
                roleName: '',
                check_style: '',
                loading:false,
                // 表格
                tableData: [],

                //  新增或者修改法人的弹窗
                dialogFormVisible: false,
                empowerVisible: false,    //赋权弹窗
                seeVisible: false,     //查看弹窗
                isPaging: false,
                pageIndex: 1,    //当前页（必传）
                pageSize: 10,   //每页多少条
                totalNumber: 20,
                totalPage: 2,
                form: {
                    id: 0,
                    roleName: '',
                    roleCode: '',
                    status: false
                },
                title:"",
                allStatus:'disable',
                //分配菜单权限
                roleId:1,
                bigPowers:[],
                permissionIdList:[],     //选中的权限

                //查看角色权限
                seeBigPowers:[],

                defaultProps: {
                    children: 'children',
                    label: 'permission'
                },
                //权限
                powerFlag:false,
                selectDisabled:false, //查询禁用
                statusDisabled:false,    //启用禁用操作按钮的禁用
                addSaveDisabled:false,    // 新增角色的保存操作按钮禁用
                updateSaveDisabled:false,   //修改角色的保存操作按钮禁用
                confirmFQDisabled:false,   //赋权弹窗中确定操作按钮禁用
                allCheckedId:[],   // 服务器返回的选中的ID 
                // 存储子节点全部被选中的一级节点id
                selectedAllIds:[],
                // 存储所有子节点包含未选中的节点id
                unselectedIdObj:{},
                // 存储服务器返回的已选中节点目录
                checkedIdObj:{},
                data_arr:[],     //一级目录的数组
                allNode:{},
                reflectArr:[]
            }
        },
        created:function(){
            var _this=this;
            _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
        },
        computed:{
            powerData(){
                return this.$store.state.powerData;
            },
            languageType(){
                return this.$store.state.languageType;
            }
        },
        watch:{
            languageType(){
                var _this=this;
                _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
            },
            powerData(){
                var _this = this;
                for(var i=0;i<_this.powerData.length;i++){
                    if(_this.powerData[i]=="ROLE_security_roleManagement_operation"){
                        //角色管理新增、修改及赋权权限
                        _this.powerFlag=true;
                    }
                }
            }
        },
        mounted: function () {
            var _this = this;
            // //ajax前后查询按钮禁用
            // $(".selectAll").ajaxStart(function(){
            //     _this.selectDisabled=true;
            // });
            // $(".selectAll").ajaxStop(function(){
            //     _this.selectDisabled=false;
            // });
            //判断权限
            for(var i=0;i<_this.powerData.length;i++){
                if(_this.powerData[i]=="ROLE_security_roleManagement_operation"){
                    //角色管理新增、修改及赋权权限
                    _this.powerFlag=true;
                }
            }
            _this.queryByPage(_this.pageIndex, _this.pageSize);
        },

        methods: {
            //分页查询点击事件（不带参数）
            queryByPage(pageIndex, pageSize) {
                var _this = this;
                _this.loading=true;
                _this.$nextTick(function () {
                    var tmp = {
                        roleName: _this.formInline.name,
                        roleCode: _this.formInline.code,
                        roleStatus: _this.formInline.status,
                        pageIndex: pageIndex,
                        pageSize: pageSize};
                    $.ajax({
                        type: 'POST',
                        url: _this.metadata_service + "role/search",
                        cache: false,
                        data: JSON.stringify(tmp),
                        dataType: 'JSON',
                        contentType: "application/json;charset=utf-8",
                        success: function (data) {
                            if (data.success) {
                                // console.log(data);
                                _this.loading=false;
                                _this.tableData = data.data.roles;
                                _this.isPaging = true;
                                _this.totalPage = data.data.totalPage;
                                _this.totalNumber = data.data.totalNumber;
                            } else
                                // console.log(data.errorMessage);
                                _this.common.errorTip(data.errorMessage);
                        }
                    });
                })
            },

            //新增角色时清空绑定的数据
            handleAdd(){
                var _this = this;
                if(this.$refs['form']) {
                    this.$refs['form'].resetFields();
                }
                _this.saveButtonFlag=true;
                _this.dialogFormVisible = true;
                _this.form = {};
                _this.title=_this.languageType=="zh"?'新增角色':'Create roles';
            },
            //修改按钮点击事件
            handleEdit(index, row){
                var _this = this;
                // if(this.$refs['form']) {
                //     this.$refs['form'].resetFields();
                // }
                _this.saveButtonFlag=false;
                _this.dialogFormVisible = true;
                _this.form=row;
                _this.title=_this.languageType=="zh"?'修改角色':'Modify roles';
                if (row.roleStatus == false) {
                    _this.allStatus = 'disable';
                } else {
                    _this.allStatus = 'start';
                }
            },
            //启用按钮点击事件
            handleOpen(index, row){
                var _this = this;
                _this.updatestatus(row.id, true);
            },
            //禁用按钮点击事件
            handleDisable(index, row){
                var _this = this;
                _this.updatestatus(row.id, false);
            },
            updatestatus(id, status) {
                var _this = this;
                var tmp = {id: id, roleStatus: status};
                _this.statusDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service + "role/updateStatus",
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            var success=_this.languageType=="zh"?'提交成功！':'Submit successfully!';
                            _this.common.successTip(success);
                            _this.handleQuery();
                        } else{
                            _this.common.errorTip(data.errorMessage);
                        }
                        _this.statusDisabled=false;    
                    }
                });
            },
            //赋权弹窗     分配菜单权限
            handleFQ(index, row){
                var _this = this;
                _this.empowerVisible = true;

                // 存储子节点全部被选中的一级节点id
                _this.selectedAllIds = [];
                // 存储所有子节点包含未选中的节点id
                _this.unselectedIdObj = {};
                // 存储服务器返回的已选中节点目录
                _this.checkedIdObj = {};
                _this.data_arr=[]; 
                _this.allNode={};
                _this.reflectArr=[];


                _this.roleName=row.roleName;
                _this.roleId=row.id;
                $.ajax({
                    type: 'GET',
                    url: _this.metadata_service + "role/"+row.id+"/permissions/list",
                    cache: false,
                    success: function (data) {
                        if (data.success) {
                            _this.bigPowers=data.data.tree; 
                            _this.permissionIdList = data.data.checkedId;
                            // // 所有选中结点的id
                            // this.allCheckedId = data.data.checkedId;
                            // // 过滤掉子节点不是全部选中的父节点
                            // _this.execute(this.allCheckedId);
                            // _this.permissionIdList=_this.ref();
                        }else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            // execute (allCheckedId) {
            //     // 存储要递归的所有数据
            //     this.data_arr = this.bigPowers;
            //     // 临时变量 存储服务器返回的已选中节点
            //     var data_checked = allCheckedId;
            //     for(var i = 0; i < data_checked.length; i++) {
            //         this.checkedIdObj[data_checked[i]] = true;
            //     }
            //     this.dataLoop();
            // },
            // ref () {
            //     for(var item in this.allNode){
            //         if(!this.unselectedIdObj[item]) this.reflectArr.push(item);
            //     }
            //     return this.reflectArr;
            // },
            // dataLoop () {
            //     // 只遍历一级节点
            //     for(var item in this.data_arr){
            //         var id = this.data_arr[item].id;
            //         // 将一级节点传入递归函数开始执行判断
            //         if(!this.isCheckedAllRecursion(this.data_arr[item], id)) {
            //             this.selectedAllIds.push(id);
            //         }
            //     }
            // },
            // isCheckedAllRecursion (data, parentId) {
            //     var curId = data.id;
            //     this.allNode[curId] = true;
            //     var childState = true;
            //     if(Array.isArray(data.children) && data.children.length) {
            //         // 子节点状态 不论是否有多个子节点 只要其中一个包含未选中节点
            //         // 则 childState 为false
            //         for(var i = 0; i < data.children.length; i++){
            //             var curState = this.isCheckedAllRecursion(data.children[i], curId);
            //             if(childState) childState = curState;
            //         }
            //     }
            //     if(!this.checkedIdObj[curId] || !childState) {
            //         this.unselectedIdObj[curId] = true;
            //         return false;
            //     }
            //     return true;
            // },
            //查看弹窗
            handleSee(index, row){
                var _this = this;
                _this.seeVisible = true;
                _this.roleName=row.roleName;
                _this.roleId=row.id;
                $.ajax({
                    type: 'GET',
                    url: _this.metadata_service + "role/viewRole",
                    cache: false,
                    data:{"roleId":_this.roleId},
                    success: function (data) {
                        if (data.success) { 
                            _this.seeBigPowers=data.data;  
                        }else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            //查询按钮点击事件
            handleQuery(){
                var _this = this;
                var tmp = {
                    roleName: _this.formInline.name,
                    roleCode: _this.formInline.code,
                    roleStatus: _this.formInline.status,
                    pageIndex: _this.pageIndex,
                    pageSize: _this.pageSize
                };
                _this.selectDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service + "role/search",
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.tableData = data.data.roles;
                            _this.isPaging = true;
                            _this.totalPage = data.data.totalPage;
                            _this.totalNumber = data.data.totalNumber;
                        } else{
                            _this.common.errorTip(data.errorMessage);
                        }
                        _this.selectDisabled=false;                            
                    }
                });
            },
            //   分页
            handleSizeChange(val) {
                // console.log(`每页 ${val} 条`);
                 var _this = this;
                _this.pageSize=val;
                _this.queryByPage(_this.pageIndex, _this.pageSize);
            },
            //点击页码分页查询点击事件
            handleCurrentChange(val) {
                // console.log(`当前页: ${val}`);
                var _this = this;
                _this.pageIndex=val;
                _this.queryByPage(_this.pageIndex, _this.pageSize);
            },
            //增加角色 保存按钮点击事件
            saveAddRoleAdd() {
                var _this = this;

                //前段校验
                this.$refs['form'].validate((valid) => {
                    if (valid) {
                        if (_this.allStatus == "start") {
                            _this.form.status = true;
                        } else {
                            _this.form.status = false;
                        }
                        var tmp = {roleName: _this.form.roleName, roleCode: _this.form.roleCode, roleStatus: _this.form.status};
                        _this.addSaveDisabled=true;
                        $.ajax({
                            type: 'POST',
                            url: _this.metadata_service + "role/add",
                            cache: false,
                            data: JSON.stringify(tmp),
                            dataType: 'JSON',
                            contentType: "application/json;charset=utf-8",
                            success: function (data) {
                                if (data.success) {
                                    _this.dialogFormVisible=false;                                    
                                    var success=_this.languageType=="zh"?'新增成功！':'Create successfully!';
                                    _this.common.successTip(success);
                                    _this.handleQuery();
                                } else{
                                    _this.common.errorTip(data.errorMessage);
                                }
                                _this.addSaveDisabled=false;    
                            }
                        });
                    } else {
                        var  err=_this.common.formErrorInfo();
                        _this.common.errorTip(err);
                    }
                });
            },
            //修改里面的保存按钮点击事件
            saveAddRoleUpdate() {
                var _this = this;
                //前端校验
                this.$refs['form'].validate((valid) => {
                    if (valid) {
                        if (_this.allStatus == "start") {
                            _this.form.status = true;
                        } else {
                            _this.form.status = false;
                        }
                        var tmp = {
                            id: _this.form.id,
                            roleName: _this.form.roleName,
                            roleCode: _this.form.roleCode,
                            roleStatus: _this.form.status
                        };
                        _this.updateSaveDisabled=true;
                        $.ajax({
                            type: 'POST',
                            url: _this.metadata_service + "role/update",
                            cache: false,
                            data: JSON.stringify(tmp),
                            dataType: 'JSON',
                            contentType: "application/json;charset=utf-8",
                            success: function (data) {
                                if (data.success) {
                                    _this.dialogFormVisible=false;                                   
                                    var success=_this.languageType=="zh"?'修改成功！':'Update successfully!';
                                    _this.common.successTip(success);
                                    _this.handleQuery();
                                } else{
                                    _this.common.errorTip(data.errorMessage);
                                }
                                _this.updateSaveDisabled=false;    
                            }
                        });
                    } else {
                        var  err=_this.common.formErrorInfo();
                        _this.common.errorTip(err);
                        return false;
                    }
             });
            },
            handleChange(value, direction, movedKeys) {
                console.log(value, direction, movedKeys);
                //操作后右面的内容   操作    操作的元素
            },
            //菜单分配权限
            //确定赋权
            handleConfirmFQ(){
                var _this = this;
                // 手动勾选的
                _this.permissionIdList=[];
                for(var i=0;i<_this.$refs.tree.getCheckedNodes().length;i++){
                    if(_this.permissionIdList.indexOf(_this.$refs.tree.getCheckedNodes()[i].id)==-1){
                        _this.permissionIdList.push(_this.$refs.tree.getCheckedNodes()[i].id);
                    }
                }
                var tmp={"roleId": _this.roleId, "roleName": _this.roleName, "permissionIdList": _this.permissionIdList};
                _this.confirmFQDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service + "role/"+_this.roleId+"/permissions/save", 
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                             _this.empowerVisible = false;
                            var success=_this.languageType=="zh"?'保存成功！':'Save successfully!';
                            _this.common.successTip(success);
                        } else{
                            _this.common.errorTip(data.errorMessage);
                        }
                        _this.confirmFQDisabled=false;    
                    }
                });

            },
            //取消赋权
            cancelFQ(){
                var _this = this;
                _this.empowerVisible = false;
            }
        }
    }
</script>